package com.bjqg.bjqg01.bjqg.activity.manufacturer.activity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjqg.bjqg01.bjqg.R;
import com.bjqg.bjqg01.bjqg.activity.BaseActivity;
import com.bjqg.bjqg01.bjqg.activity.longrange.adapter.MutipleListAdapter;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.MultipleListBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.dialog.FzDialog;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreater;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreater;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadmoreListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by bjqg01 on 2018/9/17.
 */

public class ManufacturerActivity extends BaseActivity {


    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_top_title_drawer)
    TextView tvTopTitleDrawer;
    @BindView(R.id.tv_search_top_drawer)
    TextView tvSearchTopDrawer;
    @BindView(R.id.rc_list)
    RecyclerView rcList;
    @BindView(R.id.smart)
    SmartRefreshLayout smart;
    @BindView(R.id.project_information_btn_send)
    Button projectInformationBtnSend;


    MutipleListAdapter adapter;
    List<MultipleListBean> list = new ArrayList<>();
    FzDialog.Builde dialog;
    int number = 4;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manufacturer);
        ButterKnife.bind(this);
        initdata();
        initpost();
        initreash();
    }


    @OnClick({R.id.back, R.id.project_information_btn_send})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.project_information_btn_send://新建
                Intent tonew = new Intent(this, NewWtActivity.class);
                startActivity(tonew);
                break;
        }
    }

    private void initdata() {

        tvTopTitleDrawer.setText("生产厂家委托");
        tvSearchTopDrawer.setVisibility(View.INVISIBLE);
        tvSearchTopDrawer.setText("新建");


        LinearLayoutManager leftManager = new LinearLayoutManager(this);
        leftManager.setOrientation(LinearLayoutManager.VERTICAL);
        adapter = new MutipleListAdapter(list, ManufacturerActivity.this);
        rcList.setLayoutManager(leftManager);
        rcList.setAdapter(adapter);

        adapter.setOnItemClickListener(new MutipleListAdapter.onItemClickListener() {
            @Override
            public void onItem(int position) {
                initfzdialog(position);
                dialog.create().show();
            }
        });
    }

    private void initpost() {
        for (int i = 0; i < 3; i++) {
            String id = "000000" + i;
            String ywtnumber = "000000" + i;
            String wsdjzt = "已完成";
            String ypzt = "" + i;
            String zsbh = "0000001" + i;
            String syzt = "进行中";
            String spzt = "未审批";
            String bgffzt = "未发放";
            list.add(new MultipleListBean(id, ywtnumber, wsdjzt, ypzt, zsbh, syzt, spzt, bgffzt));
        }
        adapter.notifyDataSetChanged();
    }

    private void initreash() {
        SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                //全局设置主题颜色
                layout.setPrimaryColorsId(R.color.white, R.color.colorPrimary);
                //指定为经典Header，默认是 贝塞尔雷达Header
                return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });
        //设置脚布局样式,全局有效
        SmartRefreshLayout.setDefaultRefreshFooterCreater(new DefaultRefreshFooterCreater() {
            @Override
            public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
                //指定为经典Footer，默认是 BallPulseFooter
                return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });

        smart.setEnableLoadmore(true);
        smart.setEnableLoadmoreWhenContentNotFull(true);
//        smart.autoRefresh();//进入界面自动刷新
        smart.setOnRefreshLoadmoreListener(new OnRefreshLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {//上拉

            }

            @Override
            public void onRefresh(RefreshLayout refreshlayout) {//下拉

            }
        });
    }

    private void initfzdialog(final int position) {
        dialog = new FzDialog.Builde(ManufacturerActivity.this);
        dialog.setCloseListener(new DialogInterface.OnClickListener() {//确定
            @Override
            public void onClick(DialogInterface dialog, int which) {
                initfz(position);
                dialog.dismiss();
            }
        });
        dialog.setConfireListener(new DialogInterface.OnClickListener() {//取消
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    }

    private void initfz(int position) {
        String id = "000000" + number;
        String ywtnumber = "000000" + number;
        String wsdjzt = "已完成";
        String ypzt = "" + number;
        String zsbh = "0000001" + number;
        String syzt = "进行中";
        String spzt = "未审批";
        String bgffzt = "未发放";
        list.add(new MultipleListBean(id, ywtnumber, wsdjzt, ypzt, zsbh, syzt, spzt, bgffzt));
        adapter.notifyDataSetChanged();
        number++;
    }
}
